/**
 * Form Layout by Lidiya.
 * Functional coding by Lidiya.
 */

package Forms;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.sql.Date;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Vector;

import javax.swing.BorderFactory;
import javax.swing.ComboBoxModel;
import javax.swing.DefaultComboBoxModel;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTextField;
import javax.swing.ListModel;
import javax.swing.SwingConstants;
import javax.swing.SwingUtilities;
import javax.swing.border.BevelBorder;
import javax.swing.border.LineBorder;
import javax.swing.event.ListSelectionEvent;
import javax.swing.event.ListSelectionListener;

import teComponents.*;
import Classes.PackageUtils;

import Classes.Packages;
import Classes.ProdSup;
import Classes.Product_Suppliers;
import Classes.Regions;
import Classes.Validate;


import com.toedter.calendar.JDateChooser;

/**
* This code was edited or generated using CloudGarden's Jigloo
* SWT/Swing GUI Builder, which is free for non-commercial
* use. If Jigloo is being used commercially (ie, by a corporation,
* company or business for any purpose whatever) then you
* should purchase a license for each developer using Jigloo.
* Please visit www.cloudgarden.com for details.
* Use of Jigloo implies acceptance of these licensing terms.
* A COMMERCIAL LICENSE HAS NOT BEEN PURCHASED FOR
* THIS MACHINE, SO JIGLOO OR THIS CODE CANNOT BE USED
* LEGALLY FOR ANY CORPORATE OR COMMERCIAL PURPOSE.
*/
public class PackagesForm  extends teComponents.teJinternalFrame 
{
	private teJList1 lstAll;
	private teJButton btnGo;
	private teJTextField txtsearchDesc;
	private JScrollPane jScrollPane1;
	private teJLabel lblRegion;
	private teJComboBox cbopkgRegion;
	private teJTextField txtsearchName;
	private teJButton btnDelComponents;
	private teJButton btnComponents;
	private teJLabel lblProdSupp;
	private teJList1 lstProdSupplier;
	private teJTextArea txtPkgDesc;
	private teJLabel lblsearchRegion;
	private teJComboBox cbosearchRegion;
	private teJLabel lblsearchDesc;
	private teJLabel lblsearchName;
	private teJPanel pnlSearch;
	private teJLabel lblSelectedPanel;
	private teJLabel lblPkgID;
	private teJTextField txtPkgID;
	private teJLabel lblPkgName;
	private teJTextField txtPkgName;
	private JPanel pnlSelected;
	private teJButton btnAdd;
	private teJButton btnUpdate;
	private teJButton btnClear;
	private teJButton btnDelete;
	private teJLabel lblSearch;
	private teJLabel lblAll;
	private teJLabel lblPkgBasePrice;
	private teJTextField txtPkgBasePrice;
	private teJLabel lblAgencyComm;
	private teJTextField txtAgencyComm;
	private teJLabel lblPkgDesc;
	private teJButton btnClrSearch;
	private PackageUtils pkgUt = new PackageUtils();
	
	private JDateChooser dc;
	private JDateChooser Startdc;
	private JDateChooser Enddc;
	
	private ProductSupplierForm  prspForm;
	private teJFrame MDIParent;
	
	private Packages pkg;
	
	
	//PAckagesForm public and 
	//private methods 
	//Created by Lidiya Chhailo
	
	
	public PackagesForm(teJFrame caller) 
	{
		super(caller);
		initGUI();
	}
	
	public PackagesForm() 
	{
		super();
		initGUI();
	}
	
	public Packages getPkg() 
	{
		return pkg;
	}

	public void setPkg(Packages pkg) 
	{
		this.pkg = pkg;
	}

	
	
	
	
	public void addProductsSup(ProdSup ps)
	{
		
		Product_Suppliers prsup = new Product_Suppliers();
			
		if(ps != null)
		{
			prsup.getProduct().setProdName(ps.getProdName());
			prsup.getProduct().setProductId(ps.getProdInt());
			prsup.setProductSupplierId(ps.getProdSupInt());
			prsup.getSupplier().setSupName(ps.getSupName());
			prsup.getSupplier().setSupplierId(ps.getSupInt());
			if(!txtPkgID.getText().isEmpty())
			{
				pkgUt.insertPackProdsupp(Integer.parseInt(txtPkgID.getText()), prsup.getProductSupplierId());
			}
			lstProdSupplier.addElem(prsup);
					
		}
			
		
	}
	
	private void addProdSuppWindow(teJinternalFrame fr)
	{
		MainMDIForm temp = (MainMDIForm)getTopLevelAncestor();
    	temp.addWin(fr);
	}
	
	private ProductSupplierForm  getPrdSupp() 
	{ 
		if(prspForm == null)
		{
			prspForm = new ProductSupplierForm(this);
			prspForm.setPreferredSize(new java.awt.Dimension(910, 509));
			prspForm.setBounds(0, 0, 910, 509);
		}
		return prspForm;
	}
	
	private void clearSearchPanel()
	{
		txtsearchName.setText("");
		txtsearchDesc.setText("");
		cbosearchRegion.setSelectedIndex(-1);
		
		//clear text field in DateChooser
		((JTextField)dc.getDateEditor()).setText("");
		//clear Packages List
		lstAll.clrList();
		lstAll.setWorkingBgd();
		
		
	}
	
	private void clearPkgPanel()
	{
		txtAgencyComm.setText("");
		txtPkgBasePrice.setText("");
		txtPkgID.setText("");
		txtPkgID.setEnabled(false);
		txtPkgName.setText("");
		txtPkgDesc.setText("");
		cbopkgRegion.setSelectedIndex(-1);
		//set current date
		Startdc.setDate(new java.util.Date(System.currentTimeMillis()));
		Enddc.setDate(new java.util.Date(System.currentTimeMillis()));
		
		//clear products-suppliers list
		lstProdSupplier.clrList();
		
		//clear packages list
		lstAll.clrList();
		lstAll.setWorkingBgd();
		
	}
	
/* PackagesForm Private Methods 	
	Created by Lidiya Chhailo*/
	
	private void populatePackagePanel()
	{
		
	
		 setPkg((Packages)lstAll.getSelectedValue());
		 if(pkg != null)
		 {
		   txtPkgID.setText(Integer.toString(pkg.getPkgId()));
		   txtPkgID.setEnabled(false);
		   txtPkgName.setText(pkg.getPkgName());
		   Startdc.setDate(pkg.getPkgStartDate());
		   Enddc.setDate(pkg.getPkgEndDate());
		   txtPkgDesc.setText(pkg.getPkgDesc());
		   txtAgencyComm.setText(Double.toString(pkg.getPkgAgnComm()));
		   txtPkgBasePrice.setText(Double.toString(pkg.getPkgbasePrice()));
		   int i = pkgUt.setRegionName(cbosearchRegion,pkg.getPkgRegion());
		   cbopkgRegion.setSelectedIndex(i);
		   //add products suppliers to the list 
		   pkgUt.populateProductsSuppliersLst(pkg,lstProdSupplier);
		 }
	}
	
	private Packages getPackagePanelFields()
	{
		 Packages pkg = new Packages();
		 ArrayList<String> errMsg = new ArrayList<String>();
		 boolean result = true;
		 
           if(!(txtPkgID.getText().isEmpty()))
           {
		       pkg.setPkgId(Integer.parseInt(txtPkgID.getText()));
           }
           if(txtPkgName.getText().isEmpty())
           {
              errMsg.add("A Package name must be supplied.");
              result = false;
           }
           else if(Validate.genericText(txtPkgName.getText()))
		   {
			   pkg.setPkgName(txtPkgName.getText());
			   
		   }
		   else
		   {
			   errMsg.add("The Package name field can't contain a semicolon (;) or double dash (--).");
			   result = false;
		   }
           
           if(txtPkgDesc.getText().isEmpty())
           {
        	   errMsg.add("A Package Description  must be supplied.");
               result = false;
           }
           else if(Validate.genericText(txtPkgDesc.getText()))
		   {
			   pkg.setPkgDesc(txtPkgDesc.getText());
		   }
		   else
		   {
			   errMsg.add("The Package Description field can't contain a semicolon (;) or double dash (--).");
			   result = false;
		   }
		   
           if(txtAgencyComm.getText().isEmpty())
           {
        	   errMsg.add("An Agency Commision field  must be supplied.");
               result = false;
           }
           else if (Validate.genericDouble(txtAgencyComm.getText()))
		   {
			   pkg.setPkgAgnComm((Double.parseDouble(txtAgencyComm.getText())));
		   }
		   else
		   {
			   errMsg.add("Package Agency Commissions must be numeric");
			   result = false;
		   }
		   
           if(txtPkgBasePrice.getText().isEmpty())
           {
        	   errMsg.add("A Package Base Price field  must be supplied.");
               result = false;
           }
           else if (Validate.genericDouble(txtPkgBasePrice.getText()))
		   {
			   pkg.setPkgbasePrice(Double.parseDouble(txtPkgBasePrice.getText()));
		   }
		   else
		   {
			   errMsg.add("A Package Base Price field must be numeric");
			   result = false;
		   }
		   
		   if(!txtPkgBasePrice.getText().isEmpty()  && !txtAgencyComm.getText().isEmpty())
		   {
		      double dif = pkg.getPkgbasePrice() - pkg.getPkgAgnComm() ;
		      if(dif <= 0)
		      {
			     errMsg.add("Agency Commissions must be less than base price");
			     result = false;
		      }
		   }
		   
		   if(Startdc.getDate() != null && Enddc.getDate() != null)
		   {
		        if(Validate.isFirstDateEarlierThanSecond(Startdc.getDate(), Enddc.getDate()))
		        {
		        	Calendar strt = Startdc.getCalendar();
		        	java.sql.Date orStrt = new java.sql.Date(strt.getTimeInMillis());
		        	pkg.setPkgStartDate(orStrt);
		        	
		        	Calendar edt = Enddc.getCalendar();
		        	java.sql.Date orEnd = new java.sql.Date(edt.getTimeInMillis());
		        	pkg.setPkgEndDate(orEnd);
		        }
		        else
		        {
		        	errMsg.add(" A Package Start date is late than  Package End date ");
		        	result = false; 
		        }
		   }
		   else
		   {
			   errMsg.add("A Package Start date and Package End date are not set");
			   result = false; 
		   }
		   if(cbopkgRegion.getSelectedIndex()!= -1)
		   {
			   pkg.setPkgRegion((Regions)cbopkgRegion.getSelectedItem());
		   }
		   else
		   {
			   errMsg.add("Package Region  must be set");
			   result = false; 
		   }
		   
		     if(lstProdSupplier.getListSize() != 0)
		     {
			   for(int i = 0;i<lstProdSupplier.getListSize();i++)
				{
				   Product_Suppliers ps = (Product_Suppliers)lstProdSupplier.getjListModel().getElementAt(i);
					if(ps != null)
					{
						System.out.println(ps.toString());
					   pkg.addPrd_suppId(ps.getProductSupplierId());
					}
					
				}	
		     }
		     else
		    {
		    	 errMsg.add("Packages dont have products");
		    	 result = false;
		    }
	 if(!result)
	 {
	    pkg =null;
	    lstAll.clrList();
	    for(String er:errMsg)
	    {
	    	lstAll.addElem(er);
	    }
	    //set error parameters to the list  for the error indication
	    lstAll.setErrorBgd();
	  	
	 }
		 return pkg;
	}
	
	private void populatePackageList()
	{
		String sql = "SELECT * FROM Packages";
		pkgUt.processSrchBtn(lstAll,sql);
		
	}
	
	//Created by Lidiya Chhailo
	private String validatePkgSearchCreteria()
	{
		String sql = "SELECT * FROM Packages WHERE 1=1 ";
		
		if(!(txtsearchName.getText()).isEmpty())
		{
			sql += "AND PkgName LIKE"+ " '%"+txtsearchName.getText()+"%'";
		}
		if(!(txtsearchDesc.getText()).isEmpty())
		{
			sql += "AND PkgDesc LIKE"+ " '%"+txtsearchDesc.getText()+"%'";
		}
		if(cbosearchRegion.getSelectedIndex() != -1)
		{
			Regions rg = (Regions)cbosearchRegion.getSelectedItem();
			if(rg != null)
			{
				sql += "AND RegionId LIKE"+ " '%"+rg.getRegionID()+"%'";
			}
		}
		//check if date is set
		if(dc.getDate() != null)
		{
			Calendar date = dc.getCalendar();
			java.sql.Date oDate = new java.sql.Date(date.getTimeInMillis());
			sql += "AND PkgStartDate > TO_DATE('" + oDate + "','YYYY-MM-DD')";
			
		}
		return sql;
	}
	
	
	private void initGUI() 
	{
		try 
		{
			   
				this.setTitle("Maintain Packages");
				this.setSize(908, 489);
			
			
				//maintain Packages list
				getContentPane().add(getJScrollPane1());
				

				lblAll = new teJLabel();
				getContentPane().add(lblAll);
				lblAll.setText("Packages");
				lblAll.setBounds(12, 12, 80, 18);
				lblAll.setHorizontalAlignment(SwingConstants.LEFT);
			    
			
				lblSearch = new teJLabel();
				getContentPane().add(lblSearch);
				lblSearch.setText("Search for: ");
				lblSearch.setBounds(483, 14, 110, 18);
				lblSearch.setHorizontalAlignment(SwingConstants.LEFT);
			
			
				btnAdd = new teJButton();
				getContentPane().add(btnAdd);
				btnAdd.setText("Add");
				btnAdd.setBounds(12, 382, 100, 25);
				btnAdd.setToolTipText("Add a new Package and Package/Product/Suppliers to the database, based on the information in the 'Your Selection' and 'Package Contents' panels.");
				// added by Lidiya Chhailo
				btnAdd.addActionListener(new ActionListener() {
					
					@Override
					public void actionPerformed(ActionEvent e) 
					{
						// TODO Auto-generated method stub
						System.out.println("ADD");
						int pkgId =pkgUt.processAddBtn(getPackagePanelFields(),lstAll);
						pkgUt.addProductsToPkgs(pkgId,lstProdSupplier);
					    lstAll.setSelectedIndex(0);
						//populatePackagePanel();
						populatePackageList();
					}
				});
						
				btnDelete = new teJButton();
				getContentPane().add(btnDelete);
				btnDelete.setText("Delete");
				btnDelete.setBounds(129, 382, 100, 25);
				btnDelete.setToolTipText("Delete the selected Package and related Package/Product/Supplier records.");
				// added by Lidiya Chhailo
                btnDelete.addActionListener(new ActionListener() {
					
					@Override
					public void actionPerformed(ActionEvent e)
					{
						// TODO Auto-generated method stub
						
						
						pkgUt.processDeleteBtn(lstAll);
						clearPkgPanel();
						populatePackageList();
						
					}
				});
			
				btnClear = new teJButton();
				getContentPane().add(btnClear);
				btnClear.setText("Clear");
				btnClear.setBounds(365, 382, 100, 25);
				btnClear.setToolTipText("Clears all the information in the forms and refreshes the Packages list with all packages in the database.");
				// added by Lidiya Chhailo
				btnClear.addActionListener(new ActionListener() {
					
					@Override
					public void actionPerformed(ActionEvent e) {
						// TODO Auto-generated method stub
						clearPkgPanel();
					}
				});
			
			
				btnUpdate = new teJButton();
				getContentPane().add(btnUpdate);
				btnUpdate.setText("Update");
				btnUpdate.setBounds(247, 382, 100, 25);
				btnUpdate.setToolTipText("Update the selected Package and Package/Product/Supplier records in the database.");
				// added by Lidiya Chhailo
				btnUpdate.addActionListener(new ActionListener() {
					
					@Override
					public void actionPerformed(ActionEvent e)
					{
						// TODO Auto-generated method stub
						if(lstAll.getSelectedIndex() != -1)
						{
							int pkgId = pkgUt.processUpdateBtn(getPackagePanelFields(),lstAll);
						    lstAll.setSelectedIndex(0);
							//populatePackagePanel();
							populatePackageList();
						}
					}
				});
			
				pnlSelected = new teJPanel();
				getContentPane().add(pnlSelected);
				pnlSelected.setBounds(479, 210, 415, 217);
				pnlSelected.setLayout(null);
				
					lblPkgName = new teJLabel();
					pnlSelected.add(lblPkgName);
					lblPkgName.setText("Pkg Name: ");
					lblPkgName.setBounds(102, 13, 105, 14);
					lblPkgName.setHorizontalAlignment(SwingConstants.LEFT);
				
				
					txtPkgName = new teJTextField();
					pnlSelected.add(txtPkgName);
					txtPkgName.setBounds(102, 27, 300, 18);
				
				
					txtPkgID = new teJTextField();
					pnlSelected.add(txtPkgID);
					txtPkgID.setBounds(8, 27, 82, 18);
				
				
					lblPkgID = new teJLabel();
					pnlSelected.add(lblPkgID);
					lblPkgID.setText("Pkg ID:");
					lblPkgID.setBounds(8, 13, 82, 14);
					lblPkgID.setHorizontalAlignment(SwingConstants.LEFT);
				
				
					teJLabel lblStDate = new teJLabel();
					pnlSelected.add(lblStDate);
					lblStDate.setText("Pkg Start Date: ");
					lblStDate.setBounds(8, 56, 116, 14);
					lblStDate.setHorizontalAlignment(SwingConstants.LEFT);
				
				
					Startdc = new JDateChooser();
					pnlSelected.add(Startdc);
					Startdc.setBounds(8, 70, 190, 18);
				
				
					teJLabel lblEDate = new teJLabel();
					pnlSelected.add(lblEDate);
					lblEDate.setText("Pkg End Date: ");
					lblEDate.setBounds(212, 56, 116, 14);
					lblEDate.setHorizontalAlignment(SwingConstants.LEFT);
				
				
				    Enddc = new JDateChooser();
					pnlSelected.add(Enddc);
					Enddc.setBounds(212, 70, 190, 18);
				
				
					txtPkgBasePrice = new teJTextField();
					pnlSelected.add(txtPkgBasePrice);
					txtPkgBasePrice.setBounds(8, 108, 100, 23);
				
				
					lblPkgBasePrice = new teJLabel();
					pnlSelected.add(lblPkgBasePrice);
					lblPkgBasePrice.setText("Pkg Base Price:");
					lblPkgBasePrice.setBounds(8, 94, 105, 14);
					lblPkgBasePrice.setHorizontalAlignment(SwingConstants.LEFT);
				
				
					txtAgencyComm = new teJTextField();
					pnlSelected.add(txtAgencyComm);
					txtAgencyComm.setBounds(132, 108, 100, 23);
				
				
					lblAgencyComm = new teJLabel();
					pnlSelected.add(lblAgencyComm);
					lblAgencyComm.setText("Commission:");
					lblAgencyComm.setBounds(131, 94, 139, 14);
					lblAgencyComm.setHorizontalAlignment(SwingConstants.LEFT);
				
				
					lblPkgDesc = new teJLabel();
					pnlSelected.add(lblPkgDesc);
					lblPkgDesc.setText("Pkg Desc:");
					lblPkgDesc.setBounds(8, 143, 104, 12);
					lblPkgDesc.setHorizontalAlignment(SwingConstants.LEFT);
								
					txtPkgDesc = new teJTextArea();
					pnlSelected.add(txtPkgDesc);
					txtPkgDesc.setBounds(8, 163, 392, 40);
					
						//Lidiya Chhailo Region combobox for Packages
						cbopkgRegion = new teJComboBox(pkgUt.populateRegionsCbo(cbopkgRegion));
						pnlSelected.add(cbopkgRegion);
						cbopkgRegion.setBounds(251, 108, 149, 23);
						
					
					
						lblRegion = new teJLabel();
						pnlSelected.add(lblRegion);
						lblRegion.setText("Region:");
						lblRegion.setBounds(252, 94, 50, 14);
					

			
			
				lblSelectedPanel = new teJLabel();
				getContentPane().add(lblSelectedPanel);
				lblSelectedPanel.setText("Your Selection:");
				lblSelectedPanel.setBounds(479, 190, 101, 14);
				lblSelectedPanel.setHorizontalAlignment(SwingConstants.LEFT);
			
			  
				pnlSearch = new teJPanel();
				getContentPane().add(pnlSearch);
				pnlSearch.setBounds(483, 44, 415, 140);
				pnlSearch.setLayout(null);
				
					/* Add search button and action listener for "Search" */
					btnGo = new teJButton();
					pnlSearch.add(btnGo);
					btnGo.setText("Search");
					btnGo.setBounds(314, 13, 94, 49);
					btnGo.setToolTipText("Searches the Packages table for Packages that match the parameters in the search panel.");

					//Lidiya Chhailo added Action listener for "Search" button
					btnGo.addActionListener(new ActionListener()
					{
						@Override
						public void actionPerformed(ActionEvent arg0) 
						{
							String sql = validatePkgSearchCreteria();
							pkgUt.processSrchBtn(lstAll,sql);
							lstProdSupplier.clrList();
							
						}
					});
				    
					lblsearchName = new teJLabel();
					pnlSearch.add(lblsearchName);
					lblsearchName.setText("Name: ");
					lblsearchName.setBounds(52, 20, 46, 14);
				
				
					txtsearchDesc = new teJTextField();
					pnlSearch.add(txtsearchDesc);
					txtsearchDesc.setBounds(100, 41, 208, 21);
				
				
					txtsearchName = new teJTextField();
					pnlSearch.add(txtsearchName);
					txtsearchName.setBounds(100, 16, 208, 21);
				
				
					lblsearchDesc = new teJLabel();
					pnlSearch.add(lblsearchDesc);
					lblsearchDesc.setText("Description: ");
					lblsearchDesc.setBounds(14, 46, 84, 14);
				
				
					//maintain combobox for regions
					cbosearchRegion = new teJComboBox(pkgUt.populateRegionsCbo(cbosearchRegion));
					pnlSearch.add(cbosearchRegion);
					cbosearchRegion.setBounds(102, 70, 206, 22);
					
				
				
					lblsearchRegion = new teJLabel();
					pnlSearch.add(lblsearchRegion);
					lblsearchRegion.setText("Region: ");
					lblsearchRegion.setBounds(43, 81, 55, 14);
				
			
				
					dc = new JDateChooser();
					pnlSearch.add(dc);
					dc.setBounds(101, 103, 206, 21);
					
				
					teJLabel lblsearchDate = new teJLabel();
					pnlSearch.add(lblsearchDate);
					lblsearchDate.setText("Date: ");
					lblsearchDate.setBounds(43, 110, 55, 14);
				
				
					btnClrSearch = new teJButton();
					pnlSearch.add(btnClrSearch);
					btnClrSearch.setText("Clear");
					btnClrSearch.setBounds(314, 74, 94, 49);
					btnClrSearch.setToolTipText("Clears the text fields in the search panel.");
					btnClrSearch.addActionListener(new ActionListener()
					{
						@Override
						public void actionPerformed(ActionEvent arg0) 
						{
							clearSearchPanel();
						}
					});
				
		
				
				lstProdSupplier = new teJList1();
				getContentPane().add(lstProdSupplier);
				lstProdSupplier.setBounds(12, 245, 455, 131);
			
			
				lblProdSupp = new teJLabel();
				getContentPane().add(lblProdSupp);
				lblProdSupp.setText("Package Contents");
				lblProdSupp.setBounds(12, 231, 138, 14);
				lblProdSupp.setHorizontalAlignment(SwingConstants.LEFT);
			
			
				btnComponents = new teJButton();
				getContentPane().add(btnComponents);
				btnComponents.setText("Add Package Contents");
				btnComponents.setBounds(43, 427, 159, 25);
				btnComponents.setToolTipText("Opens the Package/Supplier form to allow selection of package/supplier combinations for the selected package.");
				btnComponents.addActionListener(new ActionListener() {
					
					@Override
					public void actionPerformed(ActionEvent e) {
				        
						//getPrdSupp().setVisible(true)
						if(prspForm == null)
						{
						   addProdSuppWindow(getPrdSupp());
						}
						else
						{
							getPrdSupp().setVisible(true);
						}
						
					}
				});
			
				btnDelComponents = new teJButton();
				getContentPane().add(btnDelComponents);
				btnDelComponents.setText("Delete Package Contents");
				btnDelComponents.setBounds(259, 427, 176, 25);
				btnDelComponents.setToolTipText("Remove a package/supplier combination from the selected package.");
                btnDelComponents.addActionListener(new ActionListener() {
					
					@Override
					public void actionPerformed(ActionEvent e) 
					{
				        
						if(lstProdSupplier.getSelectedIndex() != -1)	
						{
							//we have selected product to delete
							  int val = -1;
							  if(!txtPkgID.getText().isEmpty() )
							   {
							       val = Integer.parseInt(txtPkgID.getText());
							   }
							  pkgUt.processDelComponentsBtn(lstProdSupplier,val);
							  if(pkg != null)
								  pkgUt.populateProductsSuppliersLst(pkg,lstProdSupplier);
						}
						
					}
				});
			
		}
		catch(Exception e) 
		{
			e.printStackTrace();
		}
     }  //end of initGUI
     
     private JScrollPane getJScrollPane1() {
    	 if(jScrollPane1 == null) {
    		 jScrollPane1 = new JScrollPane();
    		 jScrollPane1.setBounds(12, 42, 455, 181);
    		 {
    			 lstAll = new teJList1();
    			 jScrollPane1.setViewportView(lstAll);
    			 lstAll.addListSelectionListener(new ListSelectionListener() 
    			 {
    				 public void valueChanged(ListSelectionEvent evt) 
    				 {
    					 System.out.println("Enter Packages list  Selection changed");
    					 if (lstAll.getSelectedIndex() != -1)
    					 {
    						 
    						 populatePackagePanel();
    					 }
    				 }
    			 });
    			 lstAll.setBounds(12, 42, 455, 181);
    			 populatePackageList();
    		 }
    	 }
    	 return jScrollPane1;
     }
}	//end of class

